﻿using UtilZ.Dotnet.Ex.Model;

namespace UtilZ.Dotnet.Ex.FourierTransform
{
    /// <summary>
    /// Fourier变换类
    /// </summary>
    unsafe public partial class FourierEx
    {



        /// <summary>
        /// Radix-2 Reorder Helper Method
        /// </summary>
        /// <typeparam name="T">Sample type</typeparam>
        /// <param name="samples">Sample vector</param>
        private static void Radix2Reorder<T>(in SpanZ<T> samples) where T : struct
        {
            int length = samples.Length - 1;
            int j = 0;
            for (var i = 0; i < length; i++)
            {
                if (i < j)
                {
#if NET4_0
                    var temp = samples[i];
                    samples[i] = samples[j];
                    samples[j] = temp;
#else
                    (samples[i], samples[j]) = (samples[j], samples[i]);//交换位置i和j的值
#endif
                }

                int m = samples.Length;
                do
                {
                    m >>= 1;
                    j ^= m;
                }
                while ((j & m) == 0);
            }
        }




    }


}
